#ifndef	__CXX_VIEWS_WIDGET_WIDGET_H__
#define	__CXX_VIEWS_WIDGET_WIDGET_H__

#include "viswdgtbsc.h"
#include "events.h"
#include "vismgr/view.h"
#include "vismgr/region.h"
#include "grph/canvas.h"

namespace viswidgets
{

enum wstyle
{
	wstyle_unknown = 0,
	wstyle_win31,
	wstyle_win10,
	wstyle_common,
};

class drawing_context
{
public:
	drawing_context(view_draw_reason_e res,
		view_t* vi, region_t* rgn, visgrph::canvas* surface,
		int dx, int dy, int width, int height);
	
public:
	view_t* view(void) const {
		return m_view;
	}

	visgrph::canvas& canvas(void) {
		return m_canvas;
	}

private:
	view_t* m_view;
	region_t* m_region;
	visgrph::canvas m_canvas;
	view_draw_reason_e m_reason;
};

class WIDGET_EXPORT_API widget
{
public:
	widget(view_desc_t* desc, view_t* vi = NULL);
	widget(int left, int top, int width, int height,
		view_desc_t* desc, view_t* vi = NULL);

public:
	static void widget_draw_handler(view_draw_reason_e, view_t*, region_t*);
	static void widget_event_handler(view_event_type_e, view_t*, void*);
	
public:
	// set if the widget be shown or hidden
	void setshow(bool bshow);

	// set the position of widget
	void setpos(int left, int top, int width, int height);

public:
	view_t* getview(void) {
		return m_view;
	}

public:
	// virtuals
	virtual void on_draw(drawing_context& dc);
	virtual void on_event(view_event_type_e type, void* data);

private:
	view_t* m_view;
};

#define widget_downcast(clsname, obj)	((clsname*)((int)(obj) - (int)((widget*)((clsname*)0))))

// guid for a root view
// a root view is binding with a physical surface
extern viewid_t view_id_root;

#define widget_view_handlers \
	widget::widget_draw_handler, \
	widget::widget_event_handler

// for event handler
#define enable_event_handling()	public:void on_event(view_event_type_e, void*)
#define disable_event_handling() public:void on_event(view_event_type_e, void*) {}

}; // namespace viswidget
#endif	// __CXX_VIEWS_WIDGET_WIDGET_H__
/* EOF */

